﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace DATN.mds.TrendSuggest
{
    public partial class History : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string SearchQuery = "SELECT * FROM History";

            DataSet ds = GetData(SearchQuery);
            DataView dv;

            dv = new DataView(ds.Tables[0]);
            if (ds.Tables.Count > 0)
            {
                Grd_history.DataSource = dv;
                Grd_history.DataBind();
            }
            else
            {
                Response.Write("Unable to connect to the database.");
            }
        }

        DataSet GetData(String queryString)
        {

            // Retrieve the connection string stored in the Web.config file.
            String connectionString = ConfigurationManager.ConnectionStrings["DATNconnection"].ConnectionString;
            DataSet ds = new DataSet();
            try
            {
                // Connect to the database and run the query.
                SqlConnection connection = new SqlConnection(connectionString);
                SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);

                // Fill the DataSet.
                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                // The connection failed. Display an error message.
                Response.Write("Unable to connect to the database." + ex);
            }
            return ds;
        }

    }
}